# 模拟太原和吕梁的房价
# 城市x1    面积x2   户型x3   是否学区房x4  (1  2)   装修的风格x5  (1 2)
datas = [
    {
        "city": "吕梁",
        "area": 100,
        "rooms": 2,
        "school": 1,
        "style": 1,
        "price": 8000,
    },
    {
        "city": "吕梁",
        "area": 120,
        "rooms": 2,
        "school": 1,
        "style": 1,
        "price": 8300,
    },
    {
        "city": "吕梁",
        "area": 130,
        "rooms": 2,
        "school": 1,
        "style": 1,
        "price": 8600,
    },
    {
        "city": "吕梁",
        "area": 140,
        "rooms": 2,
        "school": 1,
        "style": 1,
        "price": 9000,
    },
    {
        "city": "吕梁",
        "area": 150,
        "rooms": 2,
        "school": 1,
        "style": 1,
        "price": 9300,
    },
    {
        "city": "吕梁",
        "area": 160,
        "rooms": 2,
        "school": 1,
        "style": 1,
        "price": 9500,
    },
    {
        "city": "吕梁",
        "area": 170,
        "rooms": 4,
        "school": 3,
        "style": 2,
        "price": 9500,
    },
    {
        "city": "吕梁",
        "area": 180,
        "rooms": 4,
        "school": 4,
        "style": 3,
        "price": 9600,
    },
    {
        "city": "吕梁",
        "area": 190,
        "rooms": 2,
        "school": 1,
        "style": 1,
        "price": 9400,
    },
    {
        "city": "太原",
        "area": 210,
        "rooms": 2,
        "school": 1,
        "style": 1,
        "price": 9200,
    },
    {
        "city": "太原",
        "area": 200,
        "rooms": 2,
        "school": 1,
        "style": 1,
        "price": 9100,
    },
    {
        "city": "太原",
        "area": 190,
        "rooms": 2,
        "school": 1,
        "style": 1,
        "price": 9000,
    },
    {
        "city": "吕梁",
        "area": 180,
        "rooms": 2,
        "school": 1,
        "style": 1,
        "price": 8900,
    },
    {
        "city": "太原",
        "area": 170,
        "rooms": 2,
        "school": 1,
        "style": 1,
        "price": 8800,
    },
    {
        "city": "太原",
        "area": 160,
        "rooms": 2,
        "school": 1,
        "style": 1,
        "price": 8700,
    },
]


import numpy as np
from datas import datas
X=[]
Y=[]
cityMark={"吕梁":1,"太原":2}
for item in datas:
    single=[]

single.append(cityMark[item["city"]])
single.append(item["rooms"])
single.append(item["school"])
single.append(item["style"])
single.append(item["area"])
X.append(single)
Y.append(item["price"])

X=np.array(X)
Y=np.array(Y)

theta=np.linalg.pinv(X.T.dot(X)).dot(Y)


print(theta)

print(theta.dot(np.array([2,100,2,1,1])))